home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-01-02 | 8.7 KB | 347 lines | [TEXT/????] |
- //
- // CXBindCtx.cpp
- //
- // Copyright (C) Microsoft Corporation, 1996
- //
- // Very basic implementation of the IBindCtx interface. We assume that we only
- // have the basic in-proc COM DLL which doesn't support the CreateBindCtx API.
- // This implementation need only support the minimum set of functionality for
- // our Netscape URL moniker.
- //
-
- #define FAR
- #include "config.h"
-
- #include <ole2.h>
- #include <dispatch.h>
- #include <wintypes.h>
- #include "CXBindCtx.h"
- #include "debug.h"
-
- CXBindCtx::~CXBindCtx()
- {
- LPXOBJECTPARAM pCurrentParam;
- LPXOBJECTPARAM pTempParam;
-
- // Useful only if our URL moniker supports BindToObject.
- // ReleaseBoundObjects();
-
- // Release any registered object parameters and destroy the list.
- for (pCurrentParam = m_pParamList; pCurrentParam != NULL; ) {
- pTempParam = pCurrentParam;
- pCurrentParam = pCurrentParam->pNextParam;
- pTempParam->punkObject->Release();
- CoTaskMemFree(pTempParam);
- }
- }
-
- //
- // CXBindCtx::Lookup
- //
-
- BOOL
- CXBindCtx::Lookup(LPOLESTR pszKey, LPXOBJECTPARAM *ppParam, BOOL fRemove)
- {
- LPXOBJECTPARAM pPrevParam;
- LPXOBJECTPARAM pCurrentParam;
-
- for (pPrevParam = NULL, pCurrentParam = m_pParamList; pCurrentParam != NULL;
- pPrevParam = pCurrentParam, pCurrentParam = pCurrentParam->pNextParam) {
- if (strcmp(pCurrentParam->key, pszKey) == 0) {
- // Remove the parameter from the list if requested.
- if (fRemove) {
- if (pPrevParam == NULL)
- m_pParamList = pCurrentParam->pNextParam;
- else
- pPrevParam->pNextParam = pCurrentParam->pNextParam;
- }
- *ppParam = pCurrentParam;
- return TRUE;
- }
- }
-
- return FALSE;
- }
-
- //
- // CXBindCtx::IUnknown::QueryInterface
- //
- // Returns a pointer to the specified interface on a component to which a
- // client currently holds an interface pointer.
- //
-
- STDMETHODIMP
- CXBindCtx::QueryInterface(REFIID riid, LPVOID *ppvObj)
- {
- HRESULT hr;
- LPVOID pv;
-
- if (riid == IID_IUnknown || riid == IID_IBindCtx) {
- pv = (LPVOID)(LPBINDCTX) this;
- ++m_cRef;
- hr = ResultFromScode(S_OK);
- } else {
- pv = NULL;
- hr = ResultFromScode(E_NOINTERFACE);
- }
-
- *ppvObj = pv;
- return hr;
- }
-
- //
- // CXBindCtx::IUnknown::AddRef
- //
- // Increments the reference count for the calling interface.
- //
-
- STDMETHODIMP_(ULONG)
- CXBindCtx::AddRef(void)
- {
- return ++m_cRef;
- }
-
- //
- // CXBindCtx::IUnknown::Release
- //
- // Decrements the reference count for the calling interface on a object. If
- // the reference count on the object falls to zero, the object is freed.
- //
-
- STDMETHODIMP_(ULONG)
- CXBindCtx::Release(void)
- {
- if (--m_cRef != 0)
- return m_cRef;
-
- delete this;
- return 0;
- }
-
- //
- // CXBindCtx::IBindCtx::RegisterObjectBound
- //
- // Calls IUnknown::AddRef on the specified object to ensure that the object
- // remains active until the bind context is released. The method stores a
- // pointer to the object in the bind context's internal list of pointers.
- //
-
- STDMETHODIMP
- CXBindCtx::RegisterObjectBound(LPUNKNOWN punk)
- {
- #pragma unused (punk)
- // Useful only if our URL moniker supports BindToObject.
- return ResultFromScode(E_NOTIMPL);
- }
-
- //
- // CXBindCtx::IBindCtx::RevokeObjectBound
- //
- // Releases the IUnknown pointer to the specified object and removes that
- // pointer from the bind context's internal list of pointers. This undoes a
- // previous call to IBindCtx::RegisterObjectBound for the same object.
- //
-
- STDMETHODIMP
- CXBindCtx::RevokeObjectBound(LPUNKNOWN punk)
- {
- #pragma unused (punk)
- // Useful only if our URL moniker supports BindToObject.
- return ResultFromScode(E_NOTIMPL);
- }
-
- //
- // CXBindCtx::IBindCtx::ReleaseBoundObjects
- //
- // Releases all pointers to all objects that were previously registered by
- // calls to IBindCtx::RegisterObjectBound.
- //
-
- STDMETHODIMP
- CXBindCtx::ReleaseBoundObjects(void)
- {
- // Useful only if our URL moniker supports BindToObject.
- return ResultFromScode(E_NOTIMPL);
- }
-
- //
- // CXBindCtx::IBindCtx::SetBindOptions
- //
- // Specifies new values for the binding parameters stored in the bind context.
- // Subsequent binding operations can call IBindCtx::GetBindOptions to retrieve
- // the parameters.
- //
-
- STDMETHODIMP
- CXBindCtx::SetBindOptions(LPBIND_OPTS pbindopts)
- {
- HRESULT hr;
-
- if (pbindopts->cbStruct == sizeof(m_bindopts)) {
- BlockMove(pbindopts, &m_bindopts, sizeof(m_bindopts));
- hr = ResultFromScode(S_OK);
- } else {
- // How we handle this differs between OLE on the Mac and Win32. For
- // now, if the size isn't a BIND_OPTS, just error out.
- hr = ResultFromScode(E_INVALIDARG);
- }
-
- return hr;
- }
-
- //
- // CXBindCtx::IBindCtx::GetBindOptions
- //
- // Returns the binding options stored in this bind context.
- //
-
- STDMETHODIMP
- CXBindCtx::GetBindOptions(LPBIND_OPTS pbindopts)
- {
- HRESULT hr;
-
- if (pbindopts->cbStruct == sizeof(m_bindopts)) {
- BlockMove(&m_bindopts, pbindopts, sizeof(m_bindopts));
- hr = ResultFromScode(S_OK);
- } else {
- // How we handle this differs between OLE on the Mac and Win32. For
- // now, if the size isn't a BIND_OPTS, just error out.
- hr = ResultFromScode(E_INVALIDARG);
- }
-
- return hr;
- }
-
- //
- // CXBindCtx::IBindCtx::GetRunningObjectTable
- //
- // Provides an interface pointer to the Running Object Table (ROT) for the
- // machine on which this bind context is running.
- //
-
- STDMETHODIMP
- CXBindCtx::GetRunningObjectTable(LPRUNNINGOBJECTTABLE *pprot)
- {
- // Useful only if our URL moniker supports BindToObject.
- *pprot = NULL;
- return ResultFromScode(E_NOTIMPL);
- }
-
- //
- // CXBindCtx::IBindCtx::RegisterObjectParam
- //
- // Stores an IUnknown pointer on the specified object under the specified key
- // in the bind context's string-keyed table of pointers.
- //
-
- STDMETHODIMP
- CXBindCtx::RegisterObjectParam(LPOLESTR pszKey, LPUNKNOWN punk)
- {
- HRESULT hr;
- LPXOBJECTPARAM pParam;
-
- if (pszKey == NULL || punk == NULL) {
- hr = ResultFromScode(E_INVALIDARG);
- } else {
- if (Lookup(pszKey, &pParam, FALSE)) {
- // Parameter with this name already exists. Release its object and
- // reuse the structure.
- pParam->punkObject->Release();
- goto SetObjectPointer;
- } else {
- if ((pParam = (LPXOBJECTPARAM) CoTaskMemAlloc(sizeof(XOBJECTPARAM) +
- strlen(pszKey))) == NULL) {
- hr = ResultFromScode(E_OUTOFMEMORY);
- } else {
- strcpy(pParam->key, pszKey);
- pParam->pNextParam = m_pParamList;
- m_pParamList = pParam;
- SetObjectPointer:
- pParam->punkObject = punk;
- punk->AddRef();
- hr = ResultFromScode(S_OK);
- }
- }
- }
-
- return hr;
- }
-
- //
- // CXBindCtx::IBindCtx::GetObjectParam
- //
- // Retrieves the pointer associated with the specified key in the bind
- // context's string-keyed table of pointers.
- //
-
- STDMETHODIMP
- CXBindCtx::GetObjectParam(LPOLESTR pszKey, LPUNKNOWN *ppunk)
- {
- HRESULT hr;
- LPUNKNOWN punk;
- LPXOBJECTPARAM pParam;
-
- if (pszKey == NULL || ppunk == NULL) {
- punk = NULL;
- hr = ResultFromScode(E_INVALIDARG);
- } else {
- if (Lookup(pszKey, &pParam, FALSE)) {
- punk = pParam->punkObject;
- punk->AddRef();
- hr = ResultFromScode(S_OK);
- } else {
- punk = NULL;
- hr = ResultFromScode(E_FAIL);
- }
- }
-
- *ppunk = punk;
- return hr;
- }
-
- //
- // CXBindCtx::IBindCtx::EnumObjectParam
- //
- // Supplies a pointer to an IEnumString interface on an enumerator that can
- // return the keys of the bind context's string-keyed table of pointers.
- //
-
- STDMETHODIMP
- CXBindCtx::EnumObjectParam(LPENUMSTRING *ppenum)
- {
- // The default OLE32 IBindCtx does not implement this method, so there's
- // no reason for us to bother.
- *ppenum = NULL;
- return ResultFromScode(E_NOTIMPL);
- }
-
- //
- // CXBindCtx::IBindCtx::RevokeObjectParam
- //
- // Removes the specified key and its associated pointer from the bind context's
- // string-keyed table of objects. The key must have previously been inserted
- // into the table with a call to IBindCtx::RegisterObjectParam.
- //
-
- STDMETHODIMP
- CXBindCtx::RevokeObjectParam(LPOLESTR pszKey)
- {
- HRESULT hr;
- LPXOBJECTPARAM pParam;
-
- if (pszKey == NULL) {
- hr = ResultFromScode(E_INVALIDARG);
- } else {
- if (Lookup(pszKey, &pParam, TRUE)) {
- pParam->punkObject->Release();
- CoTaskMemFree(pParam);
- hr = ResultFromScode(S_OK);
- } else {
- // OLE32 returns E_FAIL, not S_FALSE as the SDK documents.
- hr = ResultFromScode(E_FAIL);
- }
- }
-
- return hr;
- }
-